package com.shanzmoo.admin.web.store;

import cn.hutool.core.lang.Assert;
import com.shanzmoo.admin.domain.query.StoreMemberStockJxQuery;
import com.shanzmoo.db.store.entity.vo.StoreMemberStockVO;
import com.shanzmoo.db.store.service.IStoreMemberStockService;
import com.shanzmoo.core.manager.store.StoreMemberStockManager;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
import java.util.Objects;

/**
 * 仓储用户库存实时明细 控制层
 *
 * @author Gzhao 2021-03-08
 */
@Api(tags = "仓储-用户库存")
@RestController
@RequestMapping("/store/member-stock")
public class StoreMemberStockController {

    @Autowired
    private IStoreMemberStockService storeMemberStockService;
    @Autowired
    private StoreMemberStockManager storeMemberStockManager;

//    @ApiOperation(value = "分页列表")
//    @PostMapping("/pageList")
//    public SHttpResponse<PageRespBase<StoreMemberStockVO>> pageList(@Valid @RequestBody StoreMemberStockQuery query) {
//        PageRespBase<StoreMemberStockVO> pageList = storeMemberStockManager.queryPage(query);
//        return SHttpResponse.ok(pageList);
//    }

//    @ApiOperation(value = "添加")
//    @PostMapping("/add")
//    public SHttpResponse<Boolean> add(@Valid @RequestBody StoreMemberStockSaveDTO saveDto) {
//        storeMemberStockService.save(saveDto.convertEntity());
//        return SHttpResponse.ok(Boolean.TRUE);
//    }
//
//    @ApiOperation(value = "删除")
//    @GetMapping("/delete")
//    public SHttpResponse<Boolean> deleteById(@RequestParam(value = "id") Integer id) {
//        StoreMemberStockEntity entity = new StoreMemberStockEntity();
//        entity.setId(id);
//        storeMemberStockService.updateById(entity);
//        return SHttpResponse.ok(Boolean.TRUE);
//    }
//
//    @ApiOperation(value = "修改")
//    @PostMapping("/update")
//    public SHttpResponse<Boolean> update(@Valid @RequestBody StoreMemberStockUpdateDTO updateDto) {
//        storeMemberStockService.updateById(updateDto.convertEntity());
//        return SHttpResponse.ok(Boolean.TRUE);
//    }

    @ApiOperation(value = "分页选择列表")
    @PostMapping("/pageSelectList")
    public SHttpResponse<PageRespBase<StoreMemberStockVO>> pageSelectList(@Valid @RequestBody StoreMemberStockJxQuery query) {
        Assert.isTrue(!Objects.isNull(query.getMemberId()), "未选择用户");

        PageRespBase<StoreMemberStockVO> pageList = storeMemberStockManager.queryPage(query.convertBo());
        return SHttpResponse.ok(pageList);
    }
 }
